﻿using System;
using System.Collections.Generic;
using System.Data;
using System.IO;
using UnityEngine;

namespace Core.Log {
    public interface ILogWriter {
        void Record(string message);
        void Save();
    }

    public class DefaultLogWriter : ILogWriter {
        private List<string> lst = new();
        
        private string mDataPath;
        
        public DefaultLogWriter() {
            mDataPath = Application.dataPath + "/LOG/LOG";
        }
        
        public void Record(string message) {
            lst.Add(message);
        }

        public void Save() {
            string filePath = mDataPath + DateTime.Now.ToString();
            StreamWriter sw = null;
            try {
                sw = new StreamWriter(filePath);
                foreach (string s in lst) {
                    sw.WriteLine(s);
                }

                sw.Close();
            } catch {
                try{sw.Close();}
                catch { }
            }
        }
    }
}